package com.open4cn.simulator.core.connector;

import java.io.Serializable;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-03-14 23:47
 */
public abstract class AbstractConnector implements IConnector, Serializable {

    // 连接类型
    private ConnectorModeEnum connectorMode;

    // 连接地址
    private ConnectAddress connectAddress;

    // 连接状态
    private ConnectStatus connectStatus;


    protected AbstractConnector(ConnectorModeEnum connectorMode) {
        this.connectorMode = connectorMode;
        this.connectStatus = new ConnectStatus();
    }


    public boolean beConnected() {
        connectStatus.beConnect();
        return connectStatus.isConnected();
    }

    public boolean beClosed() {
        connectStatus.beClose();
        return connectStatus.isClosed();
    }

    @Override
    public ConnectStatus getConnectStatus() {
        return connectStatus;
    }

    @Override
    public boolean send(Object msg) {
        return false;
    }

    @Override
    public boolean isConnected() {
        return connectStatus.isConnected();
    }

    @Override
    public boolean isClosed() {
        return connectStatus.isClosed();
    }

    @Override
    public ConnectorModeEnum getConnectorMode() {
        return connectorMode;
    }

    public void setConnectAddress(ConnectAddress connectAddress) {
        this.connectAddress = connectAddress;
    }

    @Override
    public ConnectAddress getConnectAddress() {
        return connectAddress;
    }
}
